package sky.cin.framework.sfoc.core.common;

import sky.cin.framework.config.ConfigFile;
import sky.cin.framework.sfoc.core.interfaces.BeanCreator;
import sky.cin.framework.sfoc.core.interfaces.BeanDefinition;
import sky.cin.framework.sfoc.core.interfaces.BeanInterfaceFactory;
import sky.cin.framework.sfoc.core.interfaces.BeanPostProcessor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public abstract class Context {
    
    protected final List<Class<?>> classes = new ArrayList<>();
    
    protected final List<BeanPostProcessor> processors = new ArrayList<>();
    
    protected final List<BeanInterfaceFactory> factories = new ArrayList<>();
    
    protected final List<BeanCreator> creators = new ArrayList<>();
    
    protected final Map<String, BeanDefinition> beanDefinitionMap = new ConcurrentHashMap<>();
    
    protected final Map<String, Object> singletonPool = new ConcurrentHashMap<>();

    protected static ConfigFile config;

    protected void setConfigFile(ConfigFile config) {
        Context.config = config;
    }

    public static ConfigFile getApplicationConfig() {
        return config;
    }

    public abstract ConfigFile getApplicationConfigFile();

    public List<Class<?>> getClasses() {
        return classes;
    }
    
    public List<BeanPostProcessor> getProcessors() {
        return processors;
    }
    
    public List<BeanInterfaceFactory> getFactories() {
        return factories;
    }
    
    public List<BeanCreator> getCreators() {
        return creators;
    }
    
    public Map<String, BeanDefinition> getBeanDefinitionMap() {
        return beanDefinitionMap;
    }
    
    public Map<String, Object> getSingletonPool() {
        return singletonPool;
    }
    
    public abstract Object getBean(String beanName);

}
